package game.com.game;

import game.com.game.action.AbstractAction;

/**
 * Created by maizhipeng on 2017/4/20.
 */

public class Persion implements World.IWorldListener {

    protected String mName;
    protected int mPower;
    protected SleepTime mSleepTime;
    protected long mMoney;
    protected int mx = 0, my = 0;
    protected int mStatus;
    protected IPersionStatusListener mIPersionStatusListener;
    public static int SLEEP_STATUS = 0, WORK_SATUS = 1, NORMAL_STATUS = 2, DIE_STATUS = 3,WALKING_STATUS =4;
    private long mLastExpenseOrdinaryPowerTime = -1;

    public Persion(String name, IPersionStatusListener IPersionStatusListener) {
        mName = name;
        mIPersionStatusListener = IPersionStatusListener;
        World.getInstance().addIWorldListener(this);
    }

    public void addPower(int power) {
        mPower += power;
        notifyStatus(mPower, mMoney);
    }

    public void expensePower(int power) {
        mPower -= power;
        notifyStatus(mPower, mMoney);

    }

    public void addMoney(long money) {
        mMoney += money;
        notifyStatus(mPower, mMoney);

    }

    public int getPower() {
        return mPower;
    }

    public long getMoney() {
        return mMoney;
    }

    public void expenseMoney(long money) {
        mMoney -= money;
        notifyStatus(mPower, mMoney);

    }


    public int getX() {
        return mx;
    }

    public int getY() {
        return my;
    }

    private void notifyStatus(int power, long money) {
        if (mIPersionStatusListener != null) mIPersionStatusListener.onStatusResponse(power, money,World.getInstance().getTime());

    }

    public int getStatus() {
        return mStatus;
    }

    public void setStatus(int status) {
        mStatus = status;
    }


    @Override
    public void onTime(long time) {

        if (time - mLastExpenseOrdinaryPowerTime > 1000 * 60 * 60) {
            expenseOrdinaryPower();
        }
    }

    private void expenseOrdinaryPower() {
        expensePower(1);
        mLastExpenseOrdinaryPowerTime=System.currentTimeMillis();
    }

    private boolean isTimeToSleep(long time){
        boolean result =false;
        if(result){

            return true;
        }else{
            return false;
        }


    }

    public void doAction(AbstractAction abstractAction){
        abstractAction.start(this);
    }
}
